package com.ruoyi.produce.base.shift.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.produce.base.shift.domain.ProduceShiftInfo;
import com.ruoyi.produce.base.shift.service.IProduceShiftInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 班次信息
 * 控制层
 *
 * @author lsy
 */
@RestController
@RequestMapping("/produce/shiftInfo")
@Api(value = "班次信息模块", tags = "班次信息接口")
public class ProduceShiftInfoController extends BaseController {

    @Autowired
    private IProduceShiftInfoService produceShiftInfoService;

    /**
     * 获取班次信息列表
     * @param produceShiftInfo
     * @return
     */
    @ApiOperationSupport(includeParameters = {""})
    @ApiOperation(value = "获取班次列表",notes = "查询所有班次列表信息")
    @ApiImplicitParam(name = "produceShiftInfo", value = "查询所有班次列表信息()", dataType = "ProduceShiftInfo")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ProduceShiftInfo produceShiftInfo) {
        startPage();
        List<ProduceShiftInfo> produceShiftInfos = produceShiftInfoService.selectProduceShiftInfoList(produceShiftInfo);
        return getDataTable(produceShiftInfos);
    }
    /**
     * 导出班次信息
     *
     * @param produceShiftInfo
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody ProduceShiftInfo produceShiftInfo) {

        List<ProduceShiftInfo> deviceList = produceShiftInfoService.selectProduceShiftInfoList(produceShiftInfo);

        ExcelUtil<ProduceShiftInfo> util = new ExcelUtil<>(ProduceShiftInfo.class);

        return util.exportExcel(deviceList, "班次信息数据");
    }

    /**
     * 新增班次
     *
     * @param produceShiftInfo
     * @return
     */
    @ApiOperation(value = "新增班次", notes = "新增班次信息")
    @ApiImplicitParam(name = "produceShiftInfo", value = "新增班次信息", dataType = "ProduceShiftInfo")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody ProduceShiftInfo produceShiftInfo) {
        return toAjax(produceShiftInfoService.insertProduceShiftInfo(produceShiftInfo));
    }

    /**
     * 修改班次信息
     *
     * @param produceShiftInfo
     * @return
     */
    @ApiOperation(value = "修改班次信息", notes = "修改班次信息")
    @ApiImplicitParam(name = "produceShiftInfo", value = "修改班次信息", dataType = "ProduceShiftInfo")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody ProduceShiftInfo produceShiftInfo) {
        return toAjax(produceShiftInfoService.updateProduceShiftInfo(produceShiftInfo));
    }

    /**
     * 删除班次信息
     * 仅修改删除标志位
     *
     * @param produceShiftInfo
     * @return
     */
    @ApiOperation(value = "删除班次信息", notes = "删除班次信息,仅删除标志位")
    @ApiImplicitParam(name = "produceShiftInfo", value = "删除班次信息", dataType = "ProduceShiftInfo")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody ProduceShiftInfo produceShiftInfo) {
        return toAjax(produceShiftInfoService.updateProduceShiftInfoDeleteFlag(produceShiftInfo));
    }

    /**
     * 生成最新班次编号
     * @param produceShiftInfo
     * @return
     */
    @ApiOperation(value = "生成最新班次编号",notes = "用于生成最新班次编号")
    @PostMapping("/createShiftInfoId")
    public AjaxResult createShiftInfoId(@RequestBody ProduceShiftInfo produceShiftInfo) {
        produceShiftInfo.setShiftInfoId(produceShiftInfoService.createShiftInfoId());
        return AjaxResult.success(produceShiftInfo);
    }
}
